#### Tables A14-A18, Figure A10 ####
rm(list=ls());gc();gc();gc();gc();gc();gc();gc();gc()

library(stargazer)
library(dplyr)
library(plm)
library(lmtest)


here::i_am("Scripts/TabA14-A18FigA10Script.R")

library(here)


#First let's get the Michigan events:
analysis_data<-readRDS(here("Data", "analysis_data2.rds"))
              
              
#Table A14: Effects of Legislative Positions on Event Donations, Controlling for Decennial State-District Fixed Effects (TabA14.tex)####

#(1)
m1<-plm(logfriamount~factor(statechamberyear3)+factor(statedistrictcycleid)+leader+chair_no_other2+chairs_other+incmaj+incumbent_legislature,
        data=analysis_data[which(is.na(analysis_data$exc0)==T&analysis_data$limit1!=1),],index=c("cleaned_candid"),model="within")
#process for getting standard errors as in STATA
m1b<-within_intercept(m1,return.model = T)
vc1<-vcovHC(m1b, method = "arellano",cluster="group",type="sss")
m1c<-coeftest(m1b, vcov.=vc1)

#(2)
m2<-plm(logfriamount~factor(statechamberyear3)+factor(statedistrictcycleid)+leader_majleader+leader_minleader+leader_speakerpres+chair_no_other2+chairs_other+incmaj+incumbent_legislature,
        data=analysis_data[which(is.na(analysis_data$exc0)==T&analysis_data$limit1!=1),],
        index=c("cleaned_candid"),model="within")
#process for getting standard errors as in STATA
m2b<-within_intercept(m2,return.model = T)
vc2<-vcovHC(m2b, method = "arellano",cluster="group",type="sss")
m2c<-coeftest(m2b, vcov.=vc2)
#output results
stargazer(m1c,m2c,title="Table A14: Effects of Legislative Positions on Event Donations, Controlling for Decennial State- District Fixed Effects",
          column.labels=c("Ln Event Donations","Ln Event Donations"),
          out=here("Results", "TabA14.tex"),
          no.space = T,column.separate = c(1,1),dep.var.labels.include = F,
          keep=c("leader","leader_majleader","leader_minleader","leader_speakerpres","chair_no_other2","incmaj","chairs_other","incumbent_legislature"),
          order=c("leader","leader_majleader","leader_minleader","leader_speakerpres","chair_no_other2","incmaj","chairs_other","incumbent_legislature"),
          covariate.labels = c("Leader","Majority Leader","Minority Leader","Speaker/President","Main Chair","Majority Party","Other Chair","Legislative Seniority"),
          star.char = c("*", "**", "***"),digits = 2,
          add.lines = list(c("Legislator FE",paste("\\","checkmark",sep=""),paste("\\","checkmark",sep="")),
                           c("Chamber-Session-Cohort FE",paste("\\","checkmark",sep=""),paste("\\","checkmark",sep="")),
                           c("Decennial State-District FE",paste("\\","checkmark",sep=""),paste("\\","checkmark",sep="")),
                           c("Legislators","1,509","1,509")),
          omit.stat = c("rsq","f","adj.rsq"))

#show results 
stargazer(m1c,m2c,title="Table A14: Effects of Legislative Positions on Event Donations, Controlling for Decennial State- District Fixed Effects",
          column.labels=c("Ln Event Donations","Ln Event Donations"),
          no.space = T,column.separate = c(1,1),dep.var.labels.include = F,
          keep=c("leader","leader_majleader","leader_minleader","leader_speakerpres","chair_no_other2","incmaj","chairs_other","incumbent_legislature"),
          order=c("leader","leader_majleader","leader_minleader","leader_speakerpres","chair_no_other2","incmaj","chairs_other","incumbent_legislature"),
          covariate.labels = c("Leader","Majority Leader","Minority Leader","Speaker/President","Main Chair","Majority Party","Other Chair","Legislative Seniority"),
          star.char = c("*", "**", "***"),digits = 2,
          add.lines = list(c("Legislator FE",paste("\\","checkmark",sep=""),paste("\\","checkmark",sep="")),
                           c("Chamber-Session-Cohort FE",paste("\\","checkmark",sep=""),paste("\\","checkmark",sep="")),
                           c("Decennial State-District FE",paste("\\","checkmark",sep=""),paste("\\","checkmark",sep="")),
                           c("Legislators","1,509","1,509")),
          omit.stat = c("rsq","f","adj.rsq"))

#Table A15: Effects of Legislative Positions on Event Donations, Excluding Lobbyists (TabA15.tex)####

#(1)
m1<-plm(logfriamount_nl~as.factor(statechamberyear3)+leader+chair_no_other2+chairs_other+incmaj+incumbent_legislature,data=analysis_data[which(is.na(analysis_data$exc0)==T&analysis_data$limit1!=1),],index=c("cleaned_candid"),model="within")
#process for getting standard errors as in STATA
m1b<-within_intercept(m1,return.model = T)
vc1<-vcovHC(m1b, method = "arellano",cluster="group",type="sss")
m1c<-coeftest(m1b, vcov.=vc1)

#(2)
m2<-plm(logfriamount_nl~as.factor(statechamberyear3)+leader_majleader+leader_minleader+leader_speakerpres+chair_no_other2+chairs_other+incmaj+incumbent_legislature,data=analysis_data[which(is.na(analysis_data$exc0)==T&analysis_data$limit1!=1),],index=c("cleaned_candid"),model="within")
#process for getting standard errors as in STATA
m2b<-within_intercept(m2,return.model = T)
vc2<-vcovHC(m2b, method = "arellano",cluster="group",type="sss")
m2c<-coeftest(m2b, vcov.=vc2)

#output results
stargazer(m1c,m2c,title="Table A15: Effects of Legislative Positions on Event Donations, Excluding Lobbyists",
          column.labels=c("Ln Event Donations","Ln Event Donations"),     
          out=here("Results", "TabA15.tex"),
          no.space = T,column.separate = c(1,1),dep.var.labels.include = F,
          keep=c("leader","leader_majleader","leader_minleader","leader_speakerpres","chair_no_other2","incmaj","chairs_other","incumbent_legislature"),
          order=c("leader","leader_majleader","leader_minleader","leader_speakerpres","chair_no_other2","incmaj","chairs_other","incumbent_legislature"),
          covariate.labels = c("Leader","Majority Leader","Minority Leader","Speaker/President","Main Chair","Majority Party","Other Chair","Legislative Seniority"),
          star.char = c("*", "**", "***"),digits = 2,
          add.lines = list(c("Legislator FE",paste("\\","checkmark",sep=""),paste("\\","checkmark",sep="")),
                           c("Chamber-Session-Cohort FE",paste("\\","checkmark",sep=""),paste("\\","checkmark",sep="")),
                           c("Legislators","1,509","1,509")),
          omit.stat = c("rsq","f","adj.rsq"))
#show results
stargazer(m1c,m2c,title="Table A15: Effects of Legislative Positions on Event Donations, Excluding Lobbyists",
          column.labels=c("Ln Event Donations","Ln Event Donations"),
          no.space = T,column.separate = c(1,1),dep.var.labels.include = F,
          keep=c("leader","leader_majleader","leader_minleader","leader_speakerpres","chair_no_other2","incmaj","chairs_other","incumbent_legislature"),
          order=c("leader","leader_majleader","leader_minleader","leader_speakerpres","chair_no_other2","incmaj","chairs_other","incumbent_legislature"),
          covariate.labels = c("Leader","Majority Leader","Minority Leader","Speaker/President","Main Chair","Majority Party","Other Chair","Legislative Seniority"),
          star.char = c("*", "**", "***"),digits = 2,
          add.lines = list(c("Legislator FE",paste("\\","checkmark",sep=""),paste("\\","checkmark",sep="")),
                           c("Chamber-Session-Cohort FE",paste("\\","checkmark",sep=""),paste("\\","checkmark",sep="")),
                           c("Legislators","1,509","1,509")),
          omit.stat = c("rsq","f","adj.rsq"))

#Table A16: Effects of Legislative Positions on Non-Event Donations, Accounting for Constraints in Event Donations (TabA16.tex)####

#(1)
m1<-plm(lognfriamount~factor(statechamberyear3)+leader+chair_no_other2+chairs_other+incmaj+incumbent_legislature,data=analysis_data[which(is.na(analysis_data$exc0)==T&analysis_data$limit1!=1),],index=c("cleaned_candid"),model="within")
#process for getting standard errors as in STATA
#process for getting standard errors as in STATA
m1b<-within_intercept(m1,return.model = T)
vc1<-vcovHC(m1b, method = "arellano",cluster="group",type="sss")
m1c<-coeftest(m1b, vcov.=vc1)

#(2)
m2<-plm(lognfriamount~factor(statechamberyear3)+leader+chair_no_other2+chairs_other+incmaj+incumbent_legislature,data=analysis_data[which(is.na(analysis_data$exc0)==T&analysis_data$limit1!=1&analysis_data$total_ie_candid==0),],index=c("cleaned_candid"),model="within")
#process for getting standard errors as in STATA
m2b<-within_intercept(m2,return.model = T)
vc2<-vcovHC(m2b, method = "arellano",cluster="group",type="sss")
m2c<-coeftest(m2b, vcov.=vc2)

#(3)
m3<-plm(lognfriamount~factor(statechamberyear3)+leader+chair_no_other2+chairs_other+incmaj+incumbent_legislature,data=analysis_data[which(is.na(analysis_data$exc0)==T&analysis_data$limit1!=1&analysis_data$total_ie_candid>0),],index=c("cleaned_candid"),model="within")
#process for getting standard errors as in STATA
m3b<-within_intercept(m3,return.model = T)
vc3<-vcovHC(m3b, method = "arellano",cluster="group",type="sss")
m3c<-coeftest(m3b, vcov.=vc3)

#(4)
m4<-plm(lognfriamount~factor(statedistrictcycleid)+factor(statechamberyear3)+leader+chair_no_other2+chairs_other+incmaj+incumbent_legislature,data=analysis_data[which(is.na(analysis_data$exc0)==T&analysis_data$limit1!=1&analysis_data$total_ie_candid==0),],index=c("cleaned_candid"),model="within")
#process for getting standard errors as in STATA
m4b<-within_intercept(m4,return.model = T)
vc4<-vcovHC(m4b, method = "arellano",cluster="group",type="sss")
m4c<-coeftest(m4b, vcov.=vc4)

#(5)
m5<-plm(lognfriamount~factor(statedistrictcycleid)+factor(statechamberyear3)+leader+chair_no_other2+chairs_other+incmaj+incumbent_legislature,data=analysis_data[which(is.na(analysis_data$exc0)==T&analysis_data$limit1!=1&analysis_data$total_ie_candid>0),],index=c("cleaned_candid"),model="within")
#process for getting standard errors as in STATA
m5b<-within_intercept(m5,return.model = T)
vc5<-vcovHC(m5b, method = "arellano",cluster="group",type="sss")
m5c<-coeftest(m5b, vcov.=vc5)

#(6)
m6<-plm(logfriamount~factor(statedistrictcycleid)+factor(statechamberyear3)+leader+chair_no_other2+chairs_other+incmaj+incumbent_legislature,data=analysis_data[which(is.na(analysis_data$exc0)==T&analysis_data$limit1!=1&analysis_data$total_ie_candid>0),],index=c("cleaned_candid"),model="within")
#process for getting standard errors as in STATA
m6b<-within_intercept(m6,return.model = T)
vc6<-vcovHC(m6b, method = "arellano",cluster="group",type="sss")
m6c<-coeftest(m6b, vcov.=vc6)

#output results 
stargazer(m1c,m2c,m3c,m4c,m5c,m6c,title="Table A16: Effects of Legislative Positions on Non-Event Donations, Accounting for Constraints in Event Donations",
          column.labels=c("NED-Full Sample", "NED-No Events", "NED-Any Event", "NED-No Events & District FE", "NED-Any Event & District FE", "ED-Any Event & District FE"),
          no.space = T,column.separate = c(1,1),dep.var.labels.include = F,
          out=here("Results", "TabA16.tex"),
          keep=c("leader","chair_no_other2","incmaj","chairs_other","incumbent_legislature"),
          order=c("leader","chair_no_other2","incmaj","chairs_other","incumbent_legislature"),
          covariate.labels = c("Leader","Main Chair","Majority Party","Other Chair","Legislative Seniority"),
          star.char = c("*", "**", "***"),digits = 2,
          add.lines = list(c("Legislator FE",paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep="")),
                           c("Chamber-Session-Cohort FE",paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep="")),
                           c("Decennial State-District FE",paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""))),
          #  c("Legislators","1,509","1,509")),
          omit.stat = c("rsq","f","adj.rsq"))
#show results
stargazer(m1c,m2c,m3c,m4c,m5c,m6c,title="Table A16: Effects of Legislative Positions on Non-Event Donations, Accounting for Constraints in Event Donations",
          column.labels=c("NED-Full Sample", "NED-No Events", "NED-Any Event", "NED-No Events & District FE", "NED-Any Event & District FE", "ED-Any Event & District FE"),
          no.space = T,column.separate = c(1,1),dep.var.labels.include = F,
          keep=c("leader","chair_no_other2","incmaj","chairs_other","incumbent_legislature"),
          order=c("leader","chair_no_other2","incmaj","chairs_other","incumbent_legislature"),
          covariate.labels = c("Leader","Main Chair","Majority Party","Other Chair","Legislative Seniority"),
          star.char = c("*", "**", "***"),digits = 2,
          add.lines = list(c("Legislator FE",paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep="")),
                           c("Chamber-Session-Cohort FE",paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep="")),
                           c("Decennial State-District FE",paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""))),
          #  c("Legislators","1,509","1,509")),
          omit.stat = c("rsq","f","adj.rsq"))

##

analysis_data2<-analysis_data
analysis_data2<-analysis_data2[order(analysis_data2$cleaned_candid,analysis_data2$yearsess2),]
analysis_data2<-analysis_data2 %>%
  group_by(cleaned_candid) %>%
  mutate(
    Chair_plus0=chair_no_other2, 
    Chair_plus1=dplyr::lead(chair_no_other2,1), 
    Chair_plus2=dplyr::lead(chair_no_other2,2), 
    Chair_plus3=dplyr::lead(chair_no_other2,3), 
    
    Chairoth_plus0=chairs_other,           
    Chairoth_plus1=dplyr::lead(chairs_other,1),           
    Chairoth_plus2=dplyr::lead(chairs_other,2),           
    Chairoth_plus3=dplyr::lead(chairs_other,3),           
    
    Leader_plus0=leader,            
    Leader_plus1=dplyr::lead(leader,1),            
    Leader_plus2=dplyr::lead(leader,2),            
    Leader_plus3=dplyr::lead(leader,3),            
    
    IncMaj_plus0=incmaj,   
    IncMaj_plus1=dplyr::lead(incmaj,1),   
    IncMaj_plus2=dplyr::lead(incmaj,2),   
    IncMaj_plus3=dplyr::lead(incmaj,3),   
    
    incumbent_legislature_plus0=incumbent_legislature, 
    incumbent_legislature_plus1=dplyr::lead(incumbent_legislature,1), 
    incumbent_legislature_plus2=dplyr::lead(incumbent_legislature,2),  
    incumbent_legislature_plus3=dplyr::lead(incumbent_legislature,3)  
  )

m1<-plm(logfriamount~as.factor(statechamberyear3)+
          Leader_plus0+Leader_plus1+Leader_plus2+Leader_plus3+
          Chair_plus0+Chair_plus1+Chair_plus2+Chair_plus3+
          Chairoth_plus0+Chairoth_plus1+Chairoth_plus2+Chairoth_plus3+
          IncMaj_plus0+IncMaj_plus1+IncMaj_plus2+IncMaj_plus3+
          incumbent_legislature_plus0+incumbent_legislature_plus1+incumbent_legislature_plus2+incumbent_legislature_plus3,
        data=analysis_data2[which(is.na(analysis_data2$exc0)==T&analysis_data2$limit1!=1),],index=c("cleaned_candid"),model="within")

m1b<-within_intercept(m1,return.model = T)
vc1<-vcovHC(m1b, method = "arellano",cluster="group",type="sss")
m1c<-coeftest(m1b, vcov.=vc1)

##Figure A10: Effect of Legislative Positions on Pre-Treatment Event-Fundraising Marginal Effects Plot (FigA10.pdf)####
pdf(here("Results", "FigA10.pdf"),width=10,height=5)
par(mai=c(1,1,1,1),mar=c(3,8,3,3))
plot(ylab="Estimated Effect of Treatments\non Ln Amount of Event Donations",
     xlab="Sessions Relative to Treatment",
     ylim=c(-1,2),xlim=c(-3.5,0.8),yaxt="n",xaxt="n",frame.plot = FALSE,
     c(-3.2,-2.2,-1.2,-0.2),
     c(m1c[which(dimnames(m1c)[[1]]=="Leader_plus3"),1],
       m1c[which(dimnames(m1c)[[1]]=="Leader_plus2"),1],
       m1c[which(dimnames(m1c)[[1]]=="Leader_plus1"),1],
       m1c[which(dimnames(m1c)[[1]]=="Leader_plus0"),1]),pch=19,col="blue")
points( c(-2.8,-1.8,-0.8,0.2),
        c(m1c[which(dimnames(m1c)[[1]]=="Chair_plus3"),1],
          m1c[which(dimnames(m1c)[[1]]=="Chair_plus2"),1],
          m1c[which(dimnames(m1c)[[1]]=="Chair_plus1"),1],
          m1c[which(dimnames(m1c)[[1]]=="Chair_plus0"),1]),pch=19,col="red")
#axis(side=2,labels=F,at=c(-1,0,1,2), line=1)
axis(side=2,labels=c(-1,0,1,2),at=c(-1,0,1,2))
#axis(side=1,labels=F,at=c(-3,-2,-1,0), line=1)
axis(side=1,labels=c(-3,-2,-1,0),at=c(-3,-2,-1,0))

lines(c(-3.3,0.3),c(2,2),lty=2,col="lightgrey")
lines(c(-3.3,0.3),c(1,1),lty=2,col="lightgrey")
lines(c(-3.3,0.3),c(-1,-1),lty=2,col="lightgrey")
lines(c(-3.3,0.3),c(0,0),lty=2)
abline(v=-0.5,lty=2)
#add confidence intervals 
lines(c(-3.2,-3.2),
      c(m1c[which(dimnames(m1c)[[1]]=="Leader_plus3"),1]-1.64*m1c[which(dimnames(m1c)[[1]]=="Leader_plus3"),2],
        m1c[which(dimnames(m1c)[[1]]=="Leader_plus3"),1]+1.64*m1c[which(dimnames(m1c)[[1]]=="Leader_plus3"),2]),
      col="blue")
lines(c(-2.2,-2.2),
      c(m1c[which(dimnames(m1c)[[1]]=="Leader_plus2"),1]-1.64*m1c[which(dimnames(m1c)[[1]]=="Leader_plus2"),2],
        m1c[which(dimnames(m1c)[[1]]=="Leader_plus2"),1]+1.64*m1c[which(dimnames(m1c)[[1]]=="Leader_plus2"),2]),
      col="blue")
lines(c(-1.2,-1.2),
      c(m1c[which(dimnames(m1c)[[1]]=="Leader_plus1"),1]-1.64*m1c[which(dimnames(m1c)[[1]]=="Leader_plus1"),2],
        m1c[which(dimnames(m1c)[[1]]=="Leader_plus1"),1]+1.64*m1c[which(dimnames(m1c)[[1]]=="Leader_plus1"),2]),
      col="blue")
lines(c(-0.2,-0.2),
      c(m1c[which(dimnames(m1c)[[1]]=="Leader_plus0"),1]-1.64*m1c[which(dimnames(m1c)[[1]]=="Leader_plus0"),2],
        m1c[which(dimnames(m1c)[[1]]=="Leader_plus0"),1]+1.64*m1c[which(dimnames(m1c)[[1]]=="Leader_plus0"),2]),
      col="blue")

lines(c(-2.8,-2.8),
      c(m1c[which(dimnames(m1c)[[1]]=="Chair_plus3"),1]-1.64*m1c[which(dimnames(m1c)[[1]]=="Chair_plus3"),2],
        m1c[which(dimnames(m1c)[[1]]=="Chair_plus3"),1]+1.64*m1c[which(dimnames(m1c)[[1]]=="Chair_plus3"),2]),
      col="red")
lines(c(-1.8,-1.8),
      c(m1c[which(dimnames(m1c)[[1]]=="Chair_plus2"),1]-1.64*m1c[which(dimnames(m1c)[[1]]=="Chair_plus2"),2],
        m1c[which(dimnames(m1c)[[1]]=="Chair_plus2"),1]+1.64*m1c[which(dimnames(m1c)[[1]]=="Chair_plus2"),2]),
      col="red")
lines(c(-0.8,-0.8),
      c(m1c[which(dimnames(m1c)[[1]]=="Chair_plus1"),1]-1.64*m1c[which(dimnames(m1c)[[1]]=="Chair_plus1"),2],
        m1c[which(dimnames(m1c)[[1]]=="Chair_plus1"),1]+1.64*m1c[which(dimnames(m1c)[[1]]=="Chair_plus1"),2]),
      col="red")
lines(c(0.2, 0.2),
      c(m1c[which(dimnames(m1c)[[1]]=="Chair_plus0"),1]-1.64*m1c[which(dimnames(m1c)[[1]]=="Chair_plus0"),2],
        m1c[which(dimnames(m1c)[[1]]=="Chair_plus0"),1]+1.64*m1c[which(dimnames(m1c)[[1]]=="Chair_plus0"),2]),
      col="red")
legend("topleft",legend=c("Leader","Main Chair"),pch=19,col=c("blue","red"),bty = "n")
dev.off()



#Table A17: Full Results for Figure A10  (TabA17.tex)####
dimnames(m1c)[[1]][1]<-"Constant" #renaming from "(Intercept)"

#output results
stargazer(m1c,title="Table A17: Full Results for Figure A10", 
          column.labels=c("Ln Event Donations"),
          out= here("Results", "TabA17.tex"),
          no.space = T,column.separate = c(1),dep.var.labels.include = F,
          keep=c("Leader_plus0","Leader_plus1","Leader_plus2","Leader_plus3","Chair_plus0","Chair_plus1","Chair_plus2","Chair_plus3","Chairoth_plus0","Chairoth_plus1","Chairoth_plus2","Chairoth_plus3","IncMaj_plus0","IncMaj_plus1","IncMaj_plus2","IncMaj_plus3","incumbent_legislature_plus0","incumbent_legislature_plus1","incumbent_legislature_plus2","incumbent_legislature_plus3","Constant"),
          order=c("Leader_plus0","Leader_plus1","Leader_plus2","Leader_plus3","Chair_plus0","Chair_plus1","Chair_plus2","Chair_plus3","Chairoth_plus0","Chairoth_plus1","Chairoth_plus2","Chairoth_plus3","IncMaj_plus0","IncMaj_plus1","IncMaj_plus2","IncMaj_plus3","incumbent_legislature_plus0","incumbent_legislature_plus1","incumbent_legislature_plus2","incumbent_legislature_plus3","Constant"),
          covariate.labels = c("Leader, t+0","Leader, t+1","Leader, t+2","Leader, t+3","Chair_plus, t+0","Chair_plus, t+1","Chair_plus, t+2","Chair_plus, t+3","Other Chair, t+0","Other Chair, t+1","Other Chair, t+2","Other Chair, t+3","Majority Party, t+0","Majority Party, t+1","Majority Party, t+2","Majority Party, t+3","Legislative Seniority, t+0","Legislative Seniority, t+1","Legislative Seniority, t+2","Legislative Seniority, t+3","Constant"),
          star.char = c("*", "**", "***"),digits = 2,
          add.lines = list(c("Legislator FE",paste("\\","checkmark",sep="")),
                           c("Chamber-Session-Cohort FE",paste("\\","checkmark",sep=""))),
          omit.stat = c("rsq","f","adj.rsq"))

#show results
stargazer(m1c,title="Table A17: Full Results for Figure A10",
          column.labels=c("Ln Event Donations"),
          no.space = T,column.separate = c(1),dep.var.labels.include = F,
          keep=c("Leader_plus0","Leader_plus1","Leader_plus2","Leader_plus3","Chair_plus0","Chair_plus1","Chair_plus2","Chair_plus3","Chairoth_plus0","Chairoth_plus1","Chairoth_plus2","Chairoth_plus3","IncMaj_plus0","IncMaj_plus1","IncMaj_plus2","IncMaj_plus3","incumbent_legislature_plus0","incumbent_legislature_plus1","incumbent_legislature_plus2","incumbent_legislature_plus3","Constant"),
          order=c("Leader_plus0","Leader_plus1","Leader_plus2","Leader_plus3","Chair_plus0","Chair_plus1","Chair_plus2","Chair_plus3","Chairoth_plus0","Chairoth_plus1","Chairoth_plus2","Chairoth_plus3","IncMaj_plus0","IncMaj_plus1","IncMaj_plus2","IncMaj_plus3","incumbent_legislature_plus0","incumbent_legislature_plus1","incumbent_legislature_plus2","incumbent_legislature_plus3","Constant"),
          covariate.labels = c("Leader, t+0","Leader, t+1","Leader, t+2","Leader, t+3","Chair_plus, t+0","Chair_plus, t+1","Chair_plus, t+2","Chair_plus, t+3","Other Chair, t+0","Other Chair, t+1","Other Chair, t+2","Other Chair, t+3","Majority Party, t+0","Majority Party, t+1","Majority Party, t+2","Majority Party, t+3","Legislative Seniority, t+0","Legislative Seniority, t+1","Legislative Seniority, t+2","Legislative Seniority, t+3","Constant"),
          star.char = c("*", "**", "***"),digits = 2,
          add.lines = list(c("Legislator FE",paste("\\","checkmark",sep="")),
                           c("Chamber-Session-Cohort FE",paste("\\","checkmark",sep=""))),
          omit.stat = c("rsq","f","adj.rsq"))


#Table A18: Effects of Legislative Positions on Event Donations, Calibrated Extensive Margin Value (TabA18.tex)####

find_min_etotam_i<-min(analysis_data$etotam_i[which(analysis_data$etotam_i>0)])
analysis_data$etotam_i_norm<-analysis_data$etotam_i/find_min_etotam_i

analysis_data$logfriamount_w0<-analysis_data$etotam_i_norm
analysis_data$logfriamount_w0[which(analysis_data$logfriamount_w0>0)]<-log(analysis_data$etotam_i_norm[which(analysis_data$logfriamount_w0>0)])

analysis_data$logfriamount_w01<-analysis_data$etotam_i_norm
analysis_data$logfriamount_w01[which(analysis_data$logfriamount_w01>0)]<-log(analysis_data$etotam_i_norm[which(analysis_data$logfriamount_w01>0)])
analysis_data$logfriamount_w01[which(analysis_data$logfriamount_w01==0)]<- -0.1

analysis_data$logfriamount_w1<-analysis_data$etotam_i_norm
analysis_data$logfriamount_w1[which(analysis_data$logfriamount_w1>0)]<-log(analysis_data$etotam_i_norm[which(analysis_data$logfriamount_w1>0)])
analysis_data$logfriamount_w1[which(analysis_data$logfriamount_w1==0)]<- -1

analysis_data$logfriamount_w3<-analysis_data$etotam_i_norm
analysis_data$logfriamount_w3[which(analysis_data$logfriamount_w3>0)]<-log(analysis_data$etotam_i_norm[which(analysis_data$logfriamount_w3>0)])
analysis_data$logfriamount_w3[which(analysis_data$logfriamount_w3==0)]<- -3

#(1)
m1<-plm(logfriamount_w0~as.factor(statechamberyear3)+leader+chair_no_other2+chairs_other+incmaj+incumbent_legislature,data=analysis_data[which(is.na(analysis_data$exc0)==T&analysis_data$limit1!=1),],index=c("cleaned_candid"),model="within")
#process for getting standard errors as in STATA
m1b<-within_intercept(m1,return.model = T)
vc1<-vcovHC(m1b, method = "arellano",cluster="group",type="sss")
m1c<-coeftest(m1b, vcov.=vc1)

#(2)
m2<-plm(logfriamount_w01~as.factor(statechamberyear3)+leader+chair_no_other2+chairs_other+incmaj+incumbent_legislature,data=analysis_data[which(is.na(analysis_data$exc0)==T&analysis_data$limit1!=1),],index=c("cleaned_candid"),model="within")
#process for getting standard errors as in STATA
m2b<-within_intercept(m2,return.model = T)
vc2<-vcovHC(m2b, method = "arellano",cluster="group",type="sss")
m2c<-coeftest(m2b, vcov.=vc2)

#(3)
m3<-plm(logfriamount_w1~as.factor(statechamberyear3)+leader+chair_no_other2+chairs_other+incmaj+incumbent_legislature,data=analysis_data[which(is.na(analysis_data$exc0)==T&analysis_data$limit1!=1),],index=c("cleaned_candid"),model="within")
#process for getting standard errors as in STATA
m3b<-within_intercept(m3,return.model = T)
vc3<-vcovHC(m3b, method = "arellano",cluster="group",type="sss")
m3c<-coeftest(m3b, vcov.=vc3)

#(4)
m4<-plm(logfriamount_w3~as.factor(statechamberyear3)+leader+chair_no_other2+chairs_other+incmaj+incumbent_legislature,data=analysis_data[which(is.na(analysis_data$exc0)==T&analysis_data$limit1!=1),],index=c("cleaned_candid"),model="within")
#process for getting standard errors as in STATA
m4b<-within_intercept(m4,return.model = T)
vc4<-vcovHC(m4b, method = "arellano",cluster="group",type="sss")
m4c<-coeftest(m4b, vcov.=vc4)

#output results
stargazer(m1c,m2c,m3c,m4c,
          title="Table A18: Effects of Legislative Positions on Event Donations, Calibrated Extensive Margin Value",
          out=here("Results", "TabA18.tex"),
          column.labels=c("Weight=0","Weight=0.1","Weight=1","Weight=3"),
          no.space = T,column.separate = c(1,1),dep.var.labels.include = F,
          keep=c("leader","chair_no_other2","incmaj","chairs_other","incumbent_legislature"),
          order=c("leader","chair_no_other2","incmaj","chairs_other","incumbent_legislature"),
          covariate.labels = c("Leader","Main Chair","Majority Party","Other Chair","Legislative Seniority"),
          star.char = c("*", "**", "***"),digits = 2,
          add.lines = list(c("Legislator FE",paste("\\","checkmark",sep=""),paste("\\","checkmark",sep="")),
                           c("Chamber-Session-Cohort FE",paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""))),
          omit.stat = c("rsq","f","adj.rsq"))

#show results
stargazer(m1c,m2c,m3c,m4c,title="Table A18: Effects of Legislative Positions on Event Donations, Calibrated Extensive Margin Value",
          column.labels=c("Weight=0","Weight=0.1","Weight=1","Weight=3"),
          no.space = T,column.separate = c(1,1),dep.var.labels.include = F,
          keep=c("leader","chair_no_other2","incmaj","chairs_other","incumbent_legislature"),
          order=c("leader","chair_no_other2","incmaj","chairs_other","incumbent_legislature"),
          covariate.labels = c("Leader","Main Chair","Majority Party","Other Chair","Legislative Seniority"),
          star.char = c("*", "**", "***"),digits = 2,
          add.lines = list(c("Legislator FE",paste("\\","checkmark",sep=""),paste("\\","checkmark",sep="")),
                           c("Chamber-Session-Cohort FE",paste("\\","checkmark",sep=""),paste("\\","checkmark",sep=""))),
          omit.stat = c("rsq","f","adj.rsq"))





